import {
  ADD_COUNTER,
  ADD_CARTITEM
} from './mutation-types'
export default {
  addCart(context, prod) {
    return new Promise((resolve, reject) => {
      console.log(prod)
      let cartList = context.state.cartList
      // if (cartList.length > 0) {
        let oldProd = cartList.find(item => item.iid === prod.iid);
        if (oldProd) {
          // oldProd.count += prod.count
          context.commit(ADD_COUNTER, oldProd)
          resolve('商品数量加1')

        } else {
          context.commit(ADD_CARTITEM, prod)
          resolve('商品添加成功')
        }
      // } else {
      //   context.commit(ADD_CARTITEM, prod)
      //   resolve('商品添加成功')
      // }
    })


  }
}